import { dataTableProps, PaginationProps } from 'naive-ui'
import { PropType } from 'vue'
import proComponentConfig from '../config'
import { ProTableColumn, ProtableQueryItem, ProTableRequest } from './type'

export const proTableHeaderProps = {
  tableTitle: String,

  isExport: {
    type: Boolean,
    default: false
  },
  defaultIndexColume: {
    type: Boolean,
    default: true
  },
  indexColumeWidth: {
    type: [Number, String],
    default: 70
  },
  tableTools: {
    type: Boolean,
    default: true
  },
  refresh: {
    type: Boolean,
    default: true
  }
}

export const proTableBodyProps = Object.assign(
  {},
  dataTableProps,
  proTableHeaderProps,
  {
    data: Array,
    filename: String,
    columnsAlign: {
      type: String as PropType<'left' | 'center' | 'right'>,
      default: 'center'
    },
    singleLine: {
      type: Boolean,
      default: false
    },
    columns: {
      type: Array as PropType<ProTableColumn[]>,
      default: false
    },
    request: Function as PropType<ProTableRequest>,
    striped: {
      type: Boolean,
      default: true
    },
    size: {
      type: String as PropType<'small' | 'medium' | 'large'>,
      default: 'small'
    },
    card: {
      type: Boolean,
      default: false
    },
    pageIndex: Number,
    pageSize: Number
  }
)

export const proTableProps = Object.assign({}, proTableBodyProps, {
  query: Array as PropType<ProtableQueryItem[]>,
  total: {
    type: Number,
    default: 0
  },

  pagination: {
    type: [Boolean, Object as PropType<PaginationProps>],
    default: true
  },
  defaultPageIndex: {
    type: Number,
    default: 1
  },
  defaultPageSize: {
    type: Number,
    default: 10
  },
  cache: {
    type: Boolean,
    default: false
  },
  collapsed: {
    type: Boolean,
    default: true
  },
  labelWidth: [String, Number] as PropType<number | string | 'auto'>,
  labelAlign: String as PropType<'left' | 'right'>,
  searchBtnText: {
    type: String,
    default: '查询'
  },
  resetBtnText: {
    type: String,
    default: '重置'
  },
  autoHeight: {
    type: Boolean,
    default: false
  },
  relativeHeight: {
    type: Number,
    default: 0
  },
  styleType: {
    type: String,
    default: proComponentConfig.proTable.stypeType,
    validator(val) {
      return ['one', 'two', 'three', 'four'].includes(val)
    }
  },
  autoSearch: {
    type: Boolean,
    default: true
  },
  firstLineQueryCount: {
    type: Number,
    default: 3
  }
})

export const querFormProps = {
  query: Array as PropType<ProtableQueryItem[]>,
  queryData: {
    type: Object,
    default: () => ({})
  }
}
